 
#include <stdio.h>
#include <stdlib.h>

struct ListNode {
    int data;
    struct ListNode *next;
};

struct ListNode *Createlist(int n);
struct ListNode *Del_absrepeat( struct ListNode **head );
void Printlist(struct ListNode *head);
int main()
{
    struct ListNode *head = NULL,*head2=NULL;
    int n;
    scanf("%d",&n);
    head = Createlist(n);
    printf("原始链表：");
    Printlist(head);
        
   head2=Del_absrepeat( &head );
   printf("删除重复结点的链表：");
   Printlist(head);
    
   printf("被删除的结点组成的链表：");
   Printlist(head2);
   return 0;
}

void Printlist(struct ListNode *head)
{
    struct ListNode *p;
    for ( p = head; p != NULL; p = p->next )
            printf("%d ", p->data);
        printf("\n");
}
struct ListNode *Createlist(int n) {
    struct ListNode *head = NULL;
    struct ListNode *temp = NULL;

    for (int i = 0; i < n; ++i)
    {
        temp = (struct ListNode *)malloc(sizeof(struct ListNode));
        scanf("%d", &temp->data);
        temp->next = head;
        head = temp;
    }
    return head;
}
struct ListNode *Del_absrepeat(struct ListNode **head) {
    if (*head == NULL || (*head)->next == NULL) {
        return NULL;
    }

    struct ListNode *current = *head;
    struct ListNode *prev = NULL;
    struct ListNode *deletedHead = NULL;

    while (current) {
        struct ListNode *runner = current->next;
        struct ListNode *prev_runner = current;

        while (runner) {
            if (abs(runner->data) == abs(current->data)) {
                if (deletedHead == NULL) {
                    deletedHead = runner;
                } else {
                    deletedHead->next = runner;
                }
                prev_runner->next = runner->next;
                struct ListNode *temp = runner;
                runner = runner->next;
                free(temp);
            } else {
                prev_runner = runner;
                runner = runner->next;
            }
        }

        // Move this outside the inner loop but still inside the outer loop

        prev = current;
        current = current->next;
    }

    return deletedHead;
}
